package com.canaan.business.controller.pc.storehouse;

import java.util.List;

import com.canaan.business.domain.vo.StockDetailResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.storehouse.StockCheckDetail;
import com.canaan.business.service.storehouse.IStockCheckDetailService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 库存盘点任务明细Controller
 *
 * @author ruoyi
 * @date 2023-02-14
 */
@Api(tags = "库存盘点任务明细")
@RestController
@RequestMapping("/storehouse/stockCheckDetail")
public class StockCheckDetailController extends BaseController {
    @Resource
    private IStockCheckDetailService stockCheckDetailService;

    /**
     * 查询库存盘点任务明细列表
     */
    @ApiOperation(value = "查询库存盘点任务明细列表")
    @GetMapping("/list")
    public TableDataInfo list(StockCheckDetail stockCheckDetail) {
        startPage();
        List<StockCheckDetail> list = stockCheckDetailService.selectStockCheckDetailList(stockCheckDetail);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点任务明细列表
     */
    @ApiOperation(value = "导出库存盘点任务明细列表")
    @Log(title = "库存盘点任务明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockCheckDetail stockCheckDetail) {
        List<StockCheckDetail> list = stockCheckDetailService.selectStockCheckDetailList(stockCheckDetail);
        ExcelUtil<StockCheckDetail> util = new ExcelUtil<StockCheckDetail>(StockCheckDetail.class);
        util.exportExcel(response, list, "库存盘点任务明细数据");
    }

    /**
     * 获取库存盘点任务明细详细信息
     */
    @ApiOperation(value = "获取库存盘点任务明细详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockCheckDetailService.selectStockCheckDetailById(id));
    }

    /**
     * 新增库存盘点任务明细
     */
    @ApiOperation(value = "新增库存盘点任务明细")
    @Log(title = "库存盘点任务明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockCheckDetail stockCheckDetail) {
        return toAjax(stockCheckDetailService.insertStockCheckDetail(stockCheckDetail));
    }

    /**
     * 修改库存盘点任务明细
     */
    @ApiOperation(value = "修改库存盘点任务明细")
    @Log(title = "库存盘点任务明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockCheckDetail stockCheckDetail) {
        return toAjax(stockCheckDetailService.updateStockCheckDetail(stockCheckDetail));
    }

    /**
     * 删除库存盘点任务明细
     */
    @ApiOperation(value = "删除库存盘点任务明细")
    @Log(title = "库存盘点任务明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockCheckDetailService.deleteStockCheckDetailByIds(ids));
    }

    /**
     * 获取盘点结果
     */
    @ApiOperation(value = "获取盘点结果")
    @GetMapping("/getResult/{id}")
    public AjaxResult getResult(@PathVariable Long id) {
        StockDetailResultVo stockDetailResultVo = this.stockCheckDetailService.getResult(id);
        return success(stockDetailResultVo);
    }

    /**
     * PDA完成盘点
     */
    @ApiOperation(value = "PDA完成盘点")
    @PutMapping("/finish/{id}")
    public AjaxResult finish(@PathVariable Long id) {
        return toAjax(this.stockCheckDetailService.finish(id));
    }
}
